<template>
  <n-modal
      title="标题"
      :preset="'dialog'"
      style="width: 800px"
      :mask-closable="false"
      positiveText="提交"
      negativeText="取消"
      :show-icon="false"
      @positive-click="onSubmit"
  >
    <n-form
        ref="addFormRef"
        :model="modalForm"
        :inline="false"
        :rules="rules"
    >
      <n-grid :cols="24" :x-gap="24">
        <n-form-item-gi :span="12" label="字典名称" path="typeName">
          <n-input v-model:value="modalForm.typeName" clearable placeholder="请输入字典名称"/>
        </n-form-item-gi>
        <n-form-item-gi :span="12" label="字典代码" path="typeCode">
          <n-input v-model:value="modalForm.typeCode" clearable placeholder="请输入字典代码"/>
        </n-form-item-gi>
        <n-form-item-gi :span="12" label="说明" path="remark">
          <n-input v-model:value="modalForm.remark" clearable placeholder="请输入说明"/>
        </n-form-item-gi>
<!--        <n-form-item-gi :span="12" label="显示顺序" path="sort">
          <n-input-number v-model:value="modalForm.sort" clearable placeholder="请输入显示顺序" style="width: 100%"/>
        </n-form-item-gi>-->
      </n-grid>
    </n-form>
  </n-modal>
</template>
<script setup>

import {ref} from "vue";
import {addDictType} from "@/api/system/dictApi";

const emit = defineEmits(['close','get-list'])
const addFormRef = ref()
const modalForm = ref({
  typeName:'',
  typeCode:'',
  remark:'',
});
const onSubmit= ()=>{
  addFormRef.value?.validate((errors) => {
    if (!errors) {
      addDictType(modalForm.value).then(res=>{
        emit('close')
        emit('get-list')
      })
    } else {
      console.log(errors)
      // dataUtil.message.error('验证成功')
      naive.message.error("dddd")
    }
  })
  return false
}
const rules = {
  typeName: [
    {
      required: true,
      message: '名称不能为空'
    }
  ],
  typeCode: [
    {
      required: true,
      message: '代码不能为空'
    }
  ],
}
</script>
